import { compare, isInArray } from "@/utils"

export default class ObserverExtension extends StructureObserver {
     /* 任务系统3.0 lab处理任务逻辑 */
    public HandMisson():void{
        if (!this.room.memory.Task['STRUCTURE']) this.room.memory.Task['STRUCTURE'] = []
        var allmyTask = []
        for (var task of this.room.memory.Task['STRUCTURE'])
        {
            if (isInArray(task.relateStructure,this.id))
            {
                allmyTask.push(task)
            }
        }
        /* 按照优先级排序 */
        if (allmyTask.length <= 0) return
        else if (allmyTask.length > 1)
            allmyTask.sort(compare('taskLevel'))
        /* 处理任务 */
        let thisTask = allmyTask[0]
        if (thisTask.delayTick < 99995)
            thisTask.delayTick--
        switch (thisTask.Name){
            case "观察房间":{this.HandleOR();break}
        }
    }

    /* 处理房间观察的任务 */
    public HandleOR():void{
        var thisTask = this.room.getMisson('STRUCTURE','观察房间')
        if (!thisTask) return
        var disRoom = thisTask.disRoom
        for (var i of disRoom)
        {
            this.observeRoom(i)
        }
        this.room.deleteMisson_ID(thisTask.ID)
        
    }
}